﻿using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EWSEditor.CRM
{
    class ExchangeSyncIdMapping
    {
        public Guid objectid { get; set; }
        public DateTime createdon { get; set; }
        public string exchangeentryid { get; set; }
        public Guid exchangesyncidmappingid { get; set; }
        public int fromcrmchangetype { get; set; }
        public int tocrmchangetype { get; set; }
        public bool isdeletedinexchange { get; set; }
        public bool isunlinkedincrm { get; set; }
        public DateTime modifiedon { get; set; }
        public int objecttypecode { get; set; }
        public Guid ownerid { get; set; }
        public int retries { get; set; }
        public int userdecision { get; set; }
        public long versionnumber { get; set; }
        public int lastsyncerrorcode { get; set; }

        public Entity mappingentity;

        public ExchangeSyncIdMapping(Entity mapping)
        {
            mappingentity = mapping;
            createdon = (DateTime)mapping["createdon"];
            if (mapping.Contains("exchangeentryid")) { exchangeentryid = (string)mapping["exchangeentryid"]; }
            exchangesyncidmappingid = (Guid)mapping["exchangesyncidmappingid"];
            fromcrmchangetype = (int)mapping["fromcrmchangetype"];
            isdeletedinexchange = (bool)mapping["isdeletedinexchange"];
            isunlinkedincrm = (bool)mapping["isunlinkedincrm"];
            modifiedon = (DateTime)mapping["modifiedon"];
            objectid = (Guid)mapping["objectid"];
            objecttypecode = (int)mapping["objecttypecode"];
            ownerid = ((EntityReference)mapping["ownerid"]).Id;
            retries = (int)mapping["retries"];
            tocrmchangetype = (int)mapping["tocrmchangetype"];
            userdecision = (int)mapping["userdecision"];

            if (mapping.Contains("versionnumber"))
            {
                versionnumber = (long)mapping["versionnumber"];
            }

            if (mapping.Contains("lastsyncerrorcode"))
            {
                lastsyncerrorcode = (int)mapping["lastsyncerrorcode"];
            }



        }
    }
}
